package vista;
import java.awt.Dialog.ModalityType;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.ArrayList;

import javax.swing.ImageIcon;
import javax.swing.JButton;

import javax.swing.JDialog;
import javax.swing.JFrame;
import javax.swing.JScrollPane;
import javax.swing.JTable;
import javax.swing.SwingConstants;
import javax.swing.SwingUtilities;
import javax.swing.table.AbstractTableModel;
import javax.swing.table.DefaultTableModel;
import javax.swing.table.TableModel;

import util.Utilidades;

import modelo.Cliente;
import modelo.Status;
import modelo.Sucursal;
import modelo.Tarea;
import modelo.dao.Servidor;

/**
* This code was edited or generated using CloudGarden's Jigloo
* SWT/Swing GUI Builder, which is free for non-commercial
* use. If Jigloo is being used commercially (ie, by a corporation,
* company or business for any purpose whatever) then you
* should purchase a license for each developer using Jigloo.
* Please visit www.cloudgarden.com for details.
* Use of Jigloo implies acceptance of these licensing terms.
* A COMMERCIAL LICENSE HAS NOT BEEN PURCHASED FOR
* THIS MACHINE, SO JIGLOO OR THIS CODE CANNOT BE USED
* LEGALLY FOR ANY CORPORATE OR COMMERCIAL PURPOSE.
*/
public class DlgSeleccionarTarea extends javax.swing.JDialog {

	{
		//Set Look & Feel
		try {
			javax.swing.UIManager.setLookAndFeel("com.sun.java.swing.plaf.nimbus.NimbusLookAndFeel");
		} catch(Exception e) {
			e.printStackTrace();
		}
	}

	private JScrollPane jScrollPane1;
	private JButton btSalir;
	private JButton btAceptar;
	private JTable tbTareas;
	private ArrayList<Tarea> tareas=new ArrayList<Tarea>();
	private AbstractTableModel tbModelTareas=null;
	private Tarea tar=null;

	/**
	* Auto-generated main method to display this JDialog
	*/
	/*public static void main(String[] args) {
		SwingUtilities.invokeLater(new Runnable() {
			public void run() {
				JDialog dialog = new JDialog();
				DlgSeleccionarTarea inst = new DlgSeleccionarTarea(dialog);
				inst.setVisible(true);
			}
		});
	}*/
	
	public DlgSeleccionarTarea(JDialog dialog) {
		super(dialog);
		initGUI();
	}
	
	private void initGUI() {
		try {
			{
				getContentPane().setLayout(null);
				this.setTitle("Seleccionar Tarea");
				{
					jScrollPane1 = new JScrollPane();
					getContentPane().add(jScrollPane1);
					jScrollPane1.setBounds(37, 30, 376, 199);
					{
						tareas = Servidor.tareas().consultarTareas();

						tbModelTareas = new AbstractTableModel() {
							@Override
							public Object getValueAt(int fil, int col) {
								switch (col) {
								case 0: return tareas.get(fil).getDescripcion();
								}
								
								return null;
							}
							
							@Override
							public int getRowCount() {
								return tareas.size();
							}
							
							@Override
							public String getColumnName(int col) {
								switch (col) {
								case 0: return "Tareas";
								}
								
								return null;
							}
							@Override
							public int getColumnCount() {
								return 1;
							}
						};
						tbTareas = new JTable();
						jScrollPane1.setViewportView(tbTareas);
						tbTareas.setModel(tbModelTareas);
						tbTareas.setBounds(219, 34, 101, 42);
					}
				}
				{
					btAceptar = new JButton();
					getContentPane().add(btAceptar);
					btAceptar.setText("Aceptar");
					btAceptar.setIcon(new ImageIcon(getClass().getClassLoader().getResource("iconos/Aceptar.png")));
					btAceptar.setHorizontalTextPosition(JButton.CENTER);
					btAceptar.setVerticalTextPosition(JButton.BOTTOM);
					btAceptar.setBounds(248, 267, 79, 40);
				}
				{
					btSalir = new JButton();
					getContentPane().add(btSalir);
					btSalir.setText("Salir");
					btSalir.setIcon(new ImageIcon(getClass().getClassLoader().getResource("iconos/Salir.gif")));
					btSalir.setHorizontalTextPosition(JButton.CENTER);
					btSalir.setVerticalTextPosition(JButton.BOTTOM);
					btSalir.setBounds(358, 269, 79, 40);
				}
			}
			this.setSize(465, 354);
		} catch (Exception e) {
			e.printStackTrace();
		}
	}
	
	DlgSeleccionarTarea dstar=this;
	public Tarea mostrar(JDialog dialog) {
		
		setLocationRelativeTo(null);
		
		btAceptar.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent arg0) {
				  if(Utilidades.seleccion(tbTareas, dstar, "Tarea"))
					{ tar=tareas.get(dstar.tbTareas.getSelectedRow());
				      dstar.dispose();
				    }
			}
		});
		
		btSalir.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent arg0) {
			dstar.dispose();
			}
		});
		
		this.setModalityType(ModalityType.APPLICATION_MODAL);
		setVisible(true);
		return tar;
	}

}
